package JUC.第05章_中断机制_LockSupport;//自己自行停止，

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;


public class A1_volatile进行中断操作 {
    static volatile boolean isStop = false;
    public static void main(String[] args) {
        volatile的实现中断();
    }
    private static void volatile的实现中断() {
        new Thread(()->{
            while (true){
                if(isStop){
                    System.out.println("Stop");
                    break;
                }
                System.out.println("hello");
                try {TimeUnit.MILLISECONDS.sleep(5);} catch (InterruptedException e) {e.printStackTrace();}
            }
        }).start();

        //间隔时间
        try {TimeUnit.MILLISECONDS.sleep(20);} catch (InterruptedException e) {e.printStackTrace();}

        new Thread(()->{isStop=true;}).start();

    }

}
